//
//  WPMsgViewModel.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/7.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPMsgViewModel.h"
#import "WPMsgModel.h"

@implementation WPMsgViewModel
+ (void)refresMsgDataSourceWithPageNumber:(NSInteger)page andWithSuccessBlock:(void (^)(NSArray *, NSInteger))success andWithFailureBlcok:(void (^)(NSString *))failure{
    NSDictionary * params = @{@"memberid":[UserModel defaultUser].userID,
                              @"pageNumber":@(page),
                              @"pageSize":@(10)};
    [NetWorkingManager postWithUrl:@"moveSoftware/pushMessage.jhtml" requestParams:[NetWorkingManager paramsByAppendingUserInfo:params] SuccessHandler:^(id responseObject) {
        if (responseObject[@"resultType"] && [responseObject[@"resultType"] intValue]) {
            if (responseObject[@"resultMsg"] && [responseObject[@"resultMsg"] isKindOfClass:[NSArray class]]) {
                NSMutableArray * resultArr = [NSMutableArray arrayWithCapacity:0];
                for (NSDictionary * dict in responseObject[@"resultMsg"]) {
                    WPMsgModel * model = [ WPMsgModel new];
                    [model setValuesForKeysWithDictionary:dict];
                    [resultArr addObject:model];
                }
                success(resultArr, responseObject[@"totalpages"] ? [responseObject[@"totalpages"] integerValue]:1);
            }else {
                success(@[], 1);
            }
        } else {
            failure(responseObject[@"resultMsg"]?responseObject[@"resultMsg"]:@"获取网络数据失败");
        }
    } failureHandler:^(NSError *error) {
        failure(error.localizedDescription);
    }];
}
@end
